
#include <iostream>
#include <SFML/OpenGL.hpp>
#include "GameState.h"
#include "PhysicalObject.h"
#include "Player.h"
#include "Floor.h"
#include "JumpController.h"
#include "GameUi.h"
#include "GWindow.h"
#include "Wall.h"

using namespace std;
int main()
{
	glEnable(GL_TEXTURE_2D);
	sf::RenderWindow window(sf::VideoMode(800, 600), "Test");

	GameState gameState;

	TextureManager &tm = gameState.getTextureManager();
	tm.loadTexture("sm0.png");
	tm.loadTexture("sm1.png");
	tm.loadTexture("sm2.png");
	tm.loadTexture("sm3.png");
	tm.loadTexture("sm4.png");
	tm.loadTexture("sm5.png");
	tm.loadTexture("sm6.png");
	tm.loadTexture("sm7.png");
	tm.loadTexture("wn0.png");
	tm.loadTexture("wn1.png");

	Floor *floor = new Floor(&gameState);
	floor->setPosition(b2Vec2(0, -15));
	gameState.addObject(floor);

	Player *player = new Player(&gameState);
	player->setPosition(b2Vec2(-25, -5));
	player->setSize(b2Vec2(3,3));
	gameState.addObject(player);
	gameState.setPlayer(player);

	JumpController *jump = new JumpController(&gameState);
	jump->setPosition(b2Vec2(-10,-5));
	jump->setColor(0, 0, 0);
	gameState.addObject(jump);

	GWindow *gwindow = new GWindow(&gameState);
	gameState.addObject(gwindow);
	gameState.setGWindow(gwindow);

	Wall *wall = new Wall(&gameState);
	gameState.addObject(wall);
	wall->setPosition(b2Vec2(-5, 0));

  GameUi *ui = new GameUi(&gameState, &window);
  gameState.addObject(ui);
	
	sf::Clock clock;
	window.setVerticalSyncEnabled(true);

	Music music;
	music.openFromFile("./img/music.ogg");
	
	music.setLoop(true);
	music.play();
	

  while (window.isOpen())
  {
    sf::Event event;
    while (window.pollEvent(event))
    {
      if (event.type == sf::Event::Closed)
        window.close();
    }

		sf::Time time = clock.restart();
		
		gameState.update(time.asSeconds());		

		gameState.draw();
    window.display();
  }
  return 0;
}

